package com.ffms.servlet; /**
 * @author 从卿
 * @create 2022/3/10-23:59
 */

import com.ffms.dao.ShouruDao;
import com.ffms.dao.impl.BankDaoImpl;
import com.ffms.dao.impl.ShouruDaoImpl;
import com.ffms.entity.Admin;
import com.ffms.entity.Bank;
import com.ffms.entity.FamilyMember;
import com.ffms.entity.Shouru;
import com.ffms.service.AdminService;
import com.ffms.service.FamilyMemberService;
import com.ffms.service.impl.AdminServiceImpl;
import com.ffms.service.impl.FamilyMemberServiceImpl;
import sun.util.calendar.BaseCalendar;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.Date;

@WebServlet("/AddShouruServlet")
public class AddShouruServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.接收视图层传来的表单数据并封装完成对象
        request.setCharacterEncoding("UTF-8");
        String from = request.getParameter("from");
        String money = request.getParameter("money");
        Date date=Date.valueOf(request.getParameter("date"));
        String way = request.getParameter("way");
        int mssid= Integer.parseInt(request.getParameter("mssid"));
        Shouru shouru= new Shouru(from,money,date,way,mssid);
        //2

        ShouruDao shouruDao=new ShouruDaoImpl();
        int n = shouruDao.addShouru(shouru);

        //根据结果跳转到不同的页面
        if (n > 0) {

            response.sendRedirect(request.getContextPath() + "/AllShouruServlet");

        } else {
            request.setAttribute("error1", "添加账户失败");
            request.getRequestDispatcher("/admin/shouruAdd.jsp").forward(request, response);
        }
    }
}

